perm filename DICACC.FAI[PUZ,HPM] blob sn#152741 filedate 1975-04-01 generic text, type C, neo UTF8
COMMENT ⊗   VALID 00005 PAGES
C REC  PAGE   DESCRIPTION
C00001 00001
C00002 00002		TITLE	DICACC
C00003 00003	 INIWRD(SIZE,BUFFER)  initialize the alphabet tree system, with SIZE
C00004 00004	 INSWRD(TREE,WORD)  insert WORD (a string) in alphabet tree whose first
C00007 00005	 FINWRD(TREE,WORD,NLEVS)  find a pointer in alphabet tree whose first
C00009 ENDMK
C⊗;
	TITLE	DICACC
	ENTRY	INIWRD,INSWRD,FINWRD

	A←1 ↔ B←2 ↔ C←3↔ D←4 ↔ E←5 ↔ F←6 ↔ G←7
        H←10 ↔ I←11 ↔ T←13 ↔ TT←14 ↔ TTT←15
	SP←16 ↔ P←17

RETAD:	0
LTRS:	BLOCK	33		; byte pointers into node
FSPTR:	0			; free storage pointer  -CNT,,ADR



; INIWRD(SIZE,BUFFER)  initialize the alphabet tree system, with SIZE
; words begining at BUFFER

INIWRD:	POP	P,RETAD
	MOVE	A,[POINT 18,0]
	HRLZI	B,-33
LTRLP:	MOVEM	A,LTRS(B)
	IBP	A
	AOBJN	B,LTRLP
	POP	P,B
	HRRZM	B,FSPTR
	POP	P,B
	MOVN	B,B
	HRLM	B,FSPTR
	JRST	@RETAD


; INSWRD(TREE,WORD)  insert WORD (a string) in alphabet tree whose first
; block is at TREE (a word containing the address of the first block of
; the tree, passed by reference). The length WORD must be the same as the
; depth of the tree

INSWRD:	POP	P,RETAD
	POP	SP,B		;string byte pointer
	POP	SP,C		;byte count
	HRRZ	C,C
	POP	P,I		;tree address word, passed by reference
	ADD	I,[POINT 18,0,35]
	LDB	T,I		;the value of the pointer
NXCH:	JUMPE	C,DONE		;any characters left
	CAIE	C,1
	JRST	INTRMD		;if the last letter, use single word
	JUMPN	T,EXIB		; bit mask instead of 15 word block
	MOVE	TTT,FSPTR
	HRRZ	T,TTT
	AOBJP	TTT,FLUB	;test for free storage runout
	MOVEM	TTT,FSPTR
	SETZM	(T)
	DPB	T,I
EXIB:	ILDB	TT,B
	ANDI	TT,37
	MOVEI	TTT,1		;insert a bit into the appropriate
	LSH	TTT,(TT)	;place in the terminal mask
	ORM	TTT,(T)
	MOVEI	A,1
	JRST	@RETAD
INTRMD:	JUMPN	T,EXIL		;check if a block for this level exists
	MOVE	TTT,FSPTR	;fetch another node
	HRRZ	T,TTT
	ADD	TTT,[15,,15]
	JUMPL	TTT,SOMLFT	;check for having run out of free storage
FLUB:	MOVEI	A,0		;and if so return FALSE
	JRST	@RETAD
SOMLFT:	MOVEM	TTT,FSPTR
	SETZM	(T)
	HRLI	TT,(T)
	HRRI	TT,1(T)
	BLT	TT,14(T)
	DPB	T,I
EXIL:	ILDB	TT,B		;load next letter. decrement count later
	ANDI	TT,37
	MOVE	I,LTRS(TT)
	ADD	I,T
	LDB	T,I
	SOJG	C,NXCH+1
DONE:	MOVEI	A,1		;if winnage, return true
	JRST	@RETAD

; FINWRD(TREE,WORD,NLEVS)  find a pointer in alphabet tree whose first
; block is at TREE (a word containing the address of the first block of
; the tree, passed by reference), to the subtree for those words begining
; with WORD. NLEVS is number of levels in the whole tree.

FINWRD:	POP	P,RETAD
	POP	P,A		;number of levels
	POP	SP,B		;string byte pointer
	POP	SP,C		;byte count
	HRRZ	C,C
	POP	P,I		;tree address word, passed by reference
	ADD	I,[POINT 18,0,35]
	LDB	T,I
NXCH1:	JUMPE	T,.+4		;if we've run out of tree,
	JUMPE	C,.+3		;or of input string
	JUMPG	A,NOTL		;or of tree (a bug)
	SETO	T,
EXIB1:	MOVE	A,T		;return the current pointer
	JRST	@RETAD
NOTL:	CAIE	A,1		;if this is the terminal level
	JRST	INTRM1		
	JUMPE	T,EXIB1		;then check the bit map
	ILDB	TT,B
	ANDI	TT,37
	MOVEI	TTT,1		;insert a bit into the appropriate
	LSH	TTT,(TT)	;place in the terminal mask
	MOVEI	A,0
	TDNE	TTT,(T)		;and return it
	MOVEI	A,1
	JRST	@RETAD
INTRM1:	ILDB	TT,B		;load next letter. decrement count later
	ANDI	TT,37
	MOVE	I,LTRS(TT)
	ADD	I,T
	LDB	T,I
	SUBI	A,1
	SOJA	C,NXCH1

        END